/**
 * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
 *
 * 
 * @param str string字符串 
 * @return bool布尔型
 */
 function isNumeric( str ) {
  // write code here
  let sign = false,decimal = false,hasE = false
  str = str.trim()
  var len = str.length
  if(len === 0) return false
  for(let i = 0;i < len;i++){
    if(str[i] === 'e' || str[i] === 'E'){
      if(i === len-1 || i === 0) return false
      if(str[i-1]!=='.' && str[i-1] < '0' || str[i-1] > '9') return false
      if(i === 0) return false
      if(hasE) return false
      hasE = true
    }else if(str[i] === '+' || str[i] === '-'){
      if(i === len-1) return false
      if(!sign && i > 0 && str[i-1] !== 'e' && str[i-1] !== 'E') return false
      if(sign && str[i-1] !== 'e' && str[i-1] !== 'E') return false
      sign = true
    }else if(str[i] === '.'){
      if(hasE || decimal) return false
      if(i === 0 && i === len-1) {
        return false
      }
      if(str[i-1] !== '+'&& str[i-1] !== '-' && str[i-1] < '0' || str[i-1] > '9' ){
        return false
      }
      if((i === len-1) && (str[i-1] === '+' || str[i-1] === '-')) {
        return false
      }
      decimal = true
    }else if(str[i] < '0' || str[i] > '9'){
      return false
    }
  }
  return true
}
module.exports = {
  isNumeric : isNumeric
};